/*
 * bsp_i2c.c
 *
 *  Created on: 2021年8月9日
 *      Author: lihao
 */


#include "bsp_i2c.h"

#include "bsp_oled.h"
#include "string.h"
//#include "OLED_DMA.h"


extern uint8_t OLED_Buf[1024];
extern unsigned char BMP1[];

#define  EEPROM_ADDR 0xA0

#define  OLED_ADDR   0x78


void IIC_Test(void)
{

	//初始化

	HAL_I2C_StateTypeDef state = HAL_I2C_GetState(&hi2c1);   //   HAL_I2C_STATE_READY  0x20
	printf("state is :%d\r\n",state);

	HAL_I2C_ModeTypeDef mode = HAL_I2C_GetMode(&hi2c1);     //  HAL_I2C_MODE_NONE    No I2C communication on going
	printf("mode is :%d \r\n",mode);



	//read device
	HAL_StatusTypeDef ready_state = HAL_I2C_IsDeviceReady(&hi2c1,EEPROM_ADDR,2,0xff);   //HAL_ERROR

	printf("ready_state is :%d\r\n",ready_state);

	ready_state = HAL_I2C_IsDeviceReady(&hi2c1,OLED_ADDR,2,0xff);   //HAL_ERROR

	printf("OLED ready_state is :%d\r\n",ready_state);


	OLED_Init();
	printf("init ok\r\n");


	OLED_Clear();
//	OLED_Display_On();

//	OLED_ShowNum(2,2,100,3,16);


//	OLED_Set_Pos(10,1);

	HAL_Delay(1000);



	memset(OLED_Buf,0xf0,1024);
//

	int i=0;

//	HAL_I2C_Mem_Write_DMA(&hi2c1 ,0x78,0x40,I2C_MEMADD_SIZE_8BIT,data,1024);
//	HAL_I2C_Mem_Write_DMA(&hi2c1 ,0x78,0x40,I2C_MEMADD_SIZE_8BIT,data,1024);
	HAL_I2C_Mem_Write_DMA(&hi2c1 ,0x78,0x40,I2C_MEMADD_SIZE_8BIT,OLED_Buf,1024);
	HAL_Delay(500);
//	HAL_I2C_Mem_Write_DMA(&hi2c1 ,0x78,0x40,I2C_MEMADD_SIZE_8BIT,data,1024);
//	HAL_Delay(500);
//	HAL_I2C_Mem_Write_DMA(&hi2c1 ,0x78,0x40,I2C_MEMADD_SIZE_8BIT,data,1024);
//	HAL_Delay(500);

	OLED_Clear();  //清屏

	//显示字符串

//	OLED_ShowString(0,0,(uint8_t *)"hello world",11);
	memset(OLED_Buf,0x00,1024);

	OLED_ShowString(0,1,(uint8_t *)"hello world",16);

	OLED_Refresh_Gram();

	HAL_Delay(200);



	while(1)
	{

//		memset(OLED_Buf,0x00,1024);

		OLED_ShowString(0,1,(uint8_t *)"hello world",16);

		OLED_Refresh_Gram();

//		memset(OLED_Buf,i%0xff,1024);
		printf("  %d\r\n",i++);
//		OLED_Display_Off();
	}


//	OLED_Clear();
//
//	int j=1024;
//	while(j--)
//	{
//		OLED_WR_DATA(0xff);
////		HAL_Delay(10);
//	}









//int i=0;
//	while(1)
//	{
//		printf("%d\r\n",i++);
//		OLED_DrawBMP(0,0,128,8,(unsigned char *)BMP1);
//
//	}











}


